﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary1;

namespace _026类的重写和多态
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var v = new Vehicle();
            var c = new Car();
            Vehicle r = new RaceCar();
            v.Run();
            c.Run();
            r.Run();
            //Car1 car1 = new Car1();
            //Car2 car2 = new Car2();
            //Car1 car3 = new Car3();
            //car1.Driving();
            //car2.Driving();
            //car3.Driving();
        }
    }

    class Vehicle
    {

        //属性
        public int speed;
        public virtual int Speed
        {
            get
            {
                return this.speed;
            }
            set
            {
                speed = value;
            }
        }
        public virtual void Run()
        {
            Console.WriteLine("I'm running ");
            Speed=1000;
        }
    }

    class Car : Vehicle
    {
        //在Vehicle继承 相当于类的横向扩展  纵向扩展指的是类的重写等 
        //重写父类需要加上 virtual  子类需要加上override 

        private int _rpm;
        public override int Speed
        {
            get { return this._rpm; }

            set { _rpm = value * 100; }
        }

        public override void Run()
        {
            Console.WriteLine("I'm Car running ");
            _rpm = 10000;
        }
    }

    class RaceCar : Car
    {
        public override void Run()
        {
            Console.WriteLine("I'm RaceCar,and running now");
        }

    }


}
